diff --git a/mongoose.c b/mongoose.c
index 7bc6e60f08c27288acec8f9b678fc885182c6a93..6e7c35a7f887f045bc3a1ebeabef7901b9d0b12b 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -151,14 +151,14 @@ union socket_address {
 // IO buffers interface
 struct iobuf {
   char *buf;
-  int len;
-  int size;
+  size_t len;
+  size_t size;
 };
 
-void iobuf_init(struct iobuf *, int initial_size);
+void iobuf_init(struct iobuf *, size_t initial_size);
 void iobuf_free(struct iobuf *);
-int iobuf_append(struct iobuf *, const void *data, int data_size);
-void iobuf_remove(struct iobuf *, int data_size);
+size_t iobuf_append(struct iobuf *, const void *data, size_t data_size);
+void iobuf_remove(struct iobuf *, size_t data_size);
 
 // Net skeleton interface
 // Events. Meaning of event parameter (evp) is given in the comment.
@@ -270,7 +270,7 @@ int ns_hexdump(const void *buf, int len, char *dst, int dst_len);
 #define IOBUF_RESIZE_MULTIPLIER 2.0
 #endif
 
-void iobuf_init(struct iobuf *iobuf, int size) {
+void iobuf_init(struct iobuf *iobuf, size_t size) {
   iobuf->len = iobuf->size = 0;
   iobuf->buf = NULL;
 
@@ -286,24 +286,21 @@ void iobuf_free(struct iobuf *iobuf) {
   }
 }
 
-int iobuf_append(struct iobuf *io, const void *buf, int len) {
-  static const double mult = IOBUF_RESIZE_MULTIPLIER;
+size_t iobuf_append(struct iobuf *io, const void *buf, size_t len) {
   char *p = NULL;
-  int new_len = 0;
+  size_t new_len = io->len + len, new_size = new_len * IOBUF_RESIZE_MULTIPLIER;
 
-  assert(io->len >= 0);
   assert(io->len <= io->size);
 
   if (len <= 0) {
-  } else if ((new_len = io->len + len) < io->size) {
+  } else if (new_len < io->size) {
     memcpy(io->buf + io->len, buf, len);
     io->len = new_len;
-  } else if ((p = (char *)
-              NS_REALLOC(io->buf, (int) (new_len * mult))) != NULL) {
+  } else if ((p = (char *) NS_REALLOC(io->buf, new_size)) != NULL) {
     io->buf = p;
     memcpy(io->buf + io->len, buf, len);
     io->len = new_len;
-    io->size = (int) (new_len * mult);
+    io->size = new_size;
   } else {
     len = 0;
   }
@@ -311,8 +308,8 @@ int iobuf_append(struct iobuf *io, const void *buf, int len) {
   return len;
 }
 
-void iobuf_remove(struct iobuf *io, int n) {
-  if (n >= 0 && n <= io->len) {
+void iobuf_remove(struct iobuf *io, size_t n) {
+  if (n > 0 && n <= io->len) {
     memmove(io->buf, io->buf + n, io->len - n);
     io->len -= n;
   }
@@ -597,7 +594,7 @@ static struct ns_connection *accept_conn(struct ns_server *server) {
 
     ns_add_conn(server, c);
     ns_call(c, NS_ACCEPT, &sa);
-    DBG(("%p %d %p %p %d", c, c->sock, c->ssl, server->ssl_ctx, c->flags));
+    DBG(("%p %d %p %p", c, c->sock, c->ssl, server->ssl_ctx));
   }
 
   return c;